package com.ffcc.fitness.coach.service.impl;

import com.ffcc.fitness.coach.mapper.CoachMapper;
import com.ffcc.fitness.coach.pojo.dto.CoachUpdateParam;
import com.ffcc.fitness.coach.pojo.entity.Coach;
import com.ffcc.fitness.coach.pojo.vo.CoachVO;
import com.ffcc.fitness.coach.service.CoachService;
import com.ffcc.fitness.user.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CoachServiceImpl implements CoachService {
    @Autowired
    CoachMapper coachMapper;

    @Override
    public Coach update(CoachUpdateParam coachUpdateParam) {
        //接收的前端传来的参数
        log.info("修改教练信息，参数：{}", coachUpdateParam);
        Coach coach = coachMapper.selectByUsername(coachUpdateParam.getUsername());
        BeanUtils.copyProperties(coachUpdateParam, coach);
        coachMapper.update(coach);
        //修改完后，把新的用户信息返回
        return coach;
    }

    //根据传入的userId查coach表的教练信息
    @Override
    public CoachVO selectCoachByUserId(Long userId) {
        return coachMapper.selectCoachByUserId(userId);
    }
}
